package com.jiufen.Controller;


import com.jiufen.Pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/session")
@Slf4j
public class SessionTestController {

    /**
     * 设置session
     */
    @GetMapping("/setSession")
    public Result setSession(HttpSession httpSession) {
        log.info("HttpSession--{}", httpSession.hashCode());
        httpSession.setAttribute("loginUser", "jiufen");  //往session中存储数据
        return Result.success();
    }


    /**
     * 获取session
     */
    @GetMapping("/getSession")
    public Result getSession(HttpSession httpSession) {
        log.info("HttpSession-getSession-{}", httpSession.hashCode());
        Object loginUser = httpSession.getAttribute("loginUser");  //获取session中的数据
        log.info("session中的数据：{}", loginUser);
        return Result.success(loginUser);
    }

}
